package com.cheyunkeji.er.adapter.auction;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.auction.BaojiaRecordItem;
import com.cheyunkeji.er.utils.ChannelInfoUtil;
import com.cheyunkeji.er.utils.StringUtils;
import com.cheyunkeji.er.utils.TimeUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/18 19:07.
 */

public class BaojiaRecordAdapter extends MyBaseAdapter {

    public BaojiaRecordAdapter(ArrayList<BaojiaRecordItem> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder ;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_detail_baojia_record_lv_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        BaojiaRecordItem record = (BaojiaRecordItem) dataList.get(position);

//        报价车商所在通道和当前车商选择的通道相同时，才显示报价车商名称
        if(TextUtils.equals(ChannelInfoUtil.getCurrentChannelInfo().getChannel(),record.getChannel())){
            holder.tvBjCs.setText(record.getChannel_name());
        }else{
            holder.tvBjCs.setText("****车商");
        }

        holder.tvBjPrice.setText(StringUtils.getFormatedWith2Bit(record.getCallprice() / 10000.0f));
        holder.tvBjTime.setText(TimeUtils.millis2StringWithoutYMD(record.getDateline() * 1000));
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.tv_bj_time)
        TextView tvBjTime;
        @BindView(R.id.tv_bj_cs)
        TextView tvBjCs;
        @BindView(R.id.tv_bj_price)
        TextView tvBjPrice;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
